package com.java.service.impl;

import com.java.entity.PageBean;
import com.java.entity.PsLineInfo;
import com.java.mapper.PsLineInfoMapper;
import com.java.service.PsLineInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @author caiyuan
 * @version 1.0
 * @Date 2020/6/24 11:37 Dream-Seeker
 * @Description
 */
@Service
public class PsLineInfoServiceImpl implements PsLineInfoService {
    @Autowired
    PsLineInfoMapper psLineInfoMapper;

    @Override
    public PageBean<PsLineInfo> findByPageLine(Integer currentPage,
                                               String runningStatusName,
                                               String lineCode) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        PageBean<PsLineInfo> pageBean = new PageBean<PsLineInfo>();

        //每页显示的数据
        int pageSize = 5;
        pageBean.setPageSize(pageSize);

        //封装总记录数
        int totalCount = psLineInfoMapper.selectCount(runningStatusName, lineCode);
        pageBean.setTotalCount(totalCount);
//封装总页数
        double tc = totalCount;
        Double num = Math.ceil(tc / pageSize);//向上取整
        pageBean.setTotalPage(num.intValue());


        if (currentPage > pageBean.getTotalPage()) {
            //封装当前页数
            pageBean.setCurrPage(pageBean.getTotalPage());
        } else if (currentPage < 0) {
            pageBean.setCurrPage(1);
        } else {
            pageBean.setCurrPage(currentPage);
        }
        map.put("start", (currentPage - 1) * pageSize);
        map.put("size", pageBean.getPageSize());
        map.put("runningStatusName", runningStatusName);
        map.put("lineCode", lineCode);

        //封装每页显示的数据
        List<PsLineInfo> lists = psLineInfoMapper.findByPageLine(map);
        pageBean.setLists(lists);
        return pageBean;
    }

    @Override
    public Integer runningchange(Integer id,
                                 Integer isStart) {
        return psLineInfoMapper.runningchange(id, isStart);
    }



}
